<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/4/18
 * Time: 18:40
 * @copyright: ©2024 永州微聚商 网络科技有限公司
 * @link: https://www.weiJuyunke.com
 */

namespace app\admin\controller;

use app\admin\model\Config as ConfigModel;
use app\admin\model\MessageTemplate;
use app\Request;
use app\services\wechat\Offiaccount;

class  Message
{
    public function index(Request $request)
    {
        $messageTemplate = new  MessageTemplate();

        $param = $request->param();
        $where['type'] = 1;
        if (isset($param['type']) && !empty($param['type'])) {
            $where['type'] = $param['type'];
        }
        $list = $messageTemplate->where($where)->select()->toArray();
        return adminSuccess('消息模板', $list);
    }

    public function editMessage(Request $request)
    {
        $param = $request->param();
        $messageTemplate = new  MessageTemplate();
        if (isset($param['tid']) && !empty($param['tid'])) {
            $data['tid'] = $param['tid'];
        }
        if (isset($param['template_name']) && !empty($param['template_name'])) {
            $data['template_name'] = $param['template_name'];
        }

        $messageTemplate->where(['id' => $param['id']])->update($data);

        return adminSuccess('修改成功');
    }

    public function status(Request $request)
    {
        $param = $request->param();
        $messageTemplate = new  MessageTemplate();
        $messageTemplate->where(['id' => $param['id']])->update(['status' => $param['status']]);

        return adminSuccess('修改成功');
    }

    public function templateContent()
    {
        $offiaccount = new Offiaccount();
        $result = $offiaccount->templateId();
       return adminSuccess('模板',$result);
    }
}